// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: 'applet-work-2grfv6s9025afe0b'
})

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  let openid = wxContext.OPENID;
  const db = cloud.database();
  const student = db.collection('student')
  let res = await student.where({
    openid: openid
  }).get()

  if (res.data.length > 0) {
    result = res.data[0]
  } else {
    result = { name: 'nobody' }
  }
  return {
    result
  }
}